package com.SouthernWall_404.AgeSuitcase.Common.API.GuiAPI.Animation;

import com.SouthernWall_404.AgeSuitcase.Common.API.GeneralAPI;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;

public class MoveTo extends AbstractAnimation{

//    public AbstractWidget abstractWidget;
//    public int x;
//    public int y;
    public int toX;
    public int toY;
    private boolean hasSetFinalPosition = false;
    public boolean fixMode=false;
//    public int time;

//    private int now=0;
//    private float rate =0;

    public MoveTo(AbstractWidget abstractWidget,int toX,int toY,int time) {

        super(abstractWidget,time);
        this.toX=toX;
        this.toY=toY;
    }

    public MoveTo(int fromX,int fromY,AbstractWidget abstractWidget,int time) {



        super(abstractWidget,time);
        this.x=fromX;
        this.y=fromY;
        this.toX=abstractWidget.getX();
        this.toY=abstractWidget.getY();

    }

    public MoveTo(AbstractWidget abstractWidget,int toX,int toY,int time,AbstractAnimation next) {

        super(abstractWidget,time,next);
        this.toX=toX;
        this.toY=toY;
    }
    public MoveTo(int fromX,int fromY,AbstractWidget abstractWidget,int time,AbstractAnimation next) {


        super(abstractWidget,time,next);
        this.x=fromX;
        this.y=fromY;
        this.toX=abstractWidget.getX();
        this.toY=abstractWidget.getY();

    }

    @Override
    public void render(GuiGraphics guiGraphics,float partialTicks)
    {

        if(!fixMode&&isFinished())
        {
            return;
        }
        super.render(guiGraphics,partialTicks);
        if(!isFinished())
        {
            int dX=toX-x;
            int dY=toY-y;

            int currentX=x+ GeneralAPI.estimite(dX*rate);
            int currentY=y+GeneralAPI.estimite(dY*rate);

            abstractWidget.setPosition(currentX, currentY);
            abstractWidget.render(guiGraphics,currentX,currentY, partialTicks);
        }
        else
        {
            abstractWidget.setPosition(toX, toY);
            abstractWidget.render(guiGraphics,toX, toY,partialTicks);
            return;
        }
    }

    @Override
    public void ensureFinalState(GuiGraphics guiGraphics, float partialTicks) {
        guiGraphics.pose().pushPose();
        guiGraphics.setColor(1.0f, 1.0f, 1.0f, 1.0f);
        abstractWidget.setPosition(toX,toY);
        abstractWidget.render(guiGraphics, toX, toY, partialTicks);
        guiGraphics.pose().popPose();
    }
    @Override
    void customOnFinished(GuiGraphics guiGraphics, float partialTicks) {

    }
}
